/* 
 * @(#) ChangeAction.java  1.0  2004-4-22 
 * 
 * Copyright 2003 by LongTop Corporation. 
 * All rights reserved. 
 * 
 * This software is the confidential and proprietary information of 
 * LongTop Corporation ("Confidential Information").  You 
 * shall not disclose such Confidential Information and shall use 
 * it only in accordance with the terms of the license agreement 
 * you entered into with LongTop. 
 */

package com.cnc.fd.web;


import com.cnc.bas.IBasService;
import com.cnc.bas.query.PageInfo;
import com.cnc.bas.util.Constants;
import com.cnc.bas.util.LTUtil;
import com.cnc.bas.web.BasMapForm;
import com.cnc.bas.web.SecureBaseDispatchAction;
 
import com.cnc.fd.hiber.UploadServer;
import com.cnc.fd.service.FdDao;
import com.cnc.fd.service.IFdService;
import com.cnc.ssm.UserInfo;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionServlet;
 

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

/**
 * @author LW
 * @version 1.0 
 */
public class ServerAction extends SecureBaseDispatchAction {

    private FdDao fdDao = null;
    private IFdService service = null;
    private static final int defaultPageSize = 20;
    private static final int maxPageSize = 2000;
    
    public void setServlet(ActionServlet actionServlet) {
        super.setServlet(actionServlet);
        fdDao = (FdDao) this.getBean(FdDao.BEAN_ID);
        service = (IFdService)this.getBean(IFdService.BEAN_ID);
    }
    
    public ActionForward serverQuery(ActionMapping mapping,ActionForm form,HttpServletRequest request,
           HttpServletResponse response) throws Exception {       
        return mapping.findForward("search");
    }
 
    
    public ActionForward serverList(ActionMapping mapping, ActionForm form,HttpServletRequest request,
            HttpServletResponse response) throws Exception {	
	HashMap hs = ((BasMapForm) form).getHs();
	int intCurrentPage = 1;
	String currPage = request.getParameter("intCurrentPage");
	try{
		intCurrentPage = Integer.parseInt(currPage);
	}
	catch(Exception e){
	}
	
	int intTotalPages = 1;
	String totalPage = request.getParameter("intTotalPages");
	try{
		intTotalPages = Integer.parseInt(totalPage);
	}
	catch(Exception e){
		
	}
	int pageSize = (intTotalPages==-1)?maxPageSize:defaultPageSize;
	PageInfo page = new PageInfo(intCurrentPage,pageSize);
	fdDao.getUploadServer(hs,page);
	LTUtil.setPageData(request,page);	
	return mapping.findForward("list");
    }
    
    
    public ActionForward create(ActionMapping mapping, ActionForm form,HttpServletRequest request,
            HttpServletResponse response) throws Exception {	
	return mapping.findForward("edit");
    }
    
    public ActionForward add(ActionMapping mapping, ActionForm form,HttpServletRequest request,
            HttpServletResponse response) throws Exception {	
	UploadServer server  = ((UploadServerForm) form).getServer();
	boolean isExist = fdDao.checkIpExist(server.getIp());
	if(isExist) throw new Exception("您输入的IP已经存在，请确认！");
	 
	return mapping.findForward("edit");
    }
    
  
	 
    
    public ActionForward update(ActionMapping mapping, ActionForm form,HttpServletRequest request,
            HttpServletResponse response) throws Exception {	
	UploadServer server  = ((UploadServerForm) form).getServer();
	boolean isExist = fdDao.checkIpExist(server.getIp());
	String oldServer = request.getParameter("oldServer");
	if(!oldServer.equals(server.getIp())){ if(isExist) throw new Exception("您输入的IP已经存在，请确认！");}	
	 
	return mapping.findForward("edit");
    }
    
    public ActionForward delete(ActionMapping mapping, ActionForm form,HttpServletRequest request,
            HttpServletResponse response) throws Exception {	
	String id = request.getParameter("id");	
	 
	return mapping.findForward("error");
    }
    
   
}

